package yunjiao.javatutorials.designpatterns.builder;

import lombok.Getter;
import yunjiao.javatutorials.designpatterns.builder.meal.FoodItem;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 订单
 *
 * @author yangyunjiao
 */
@Getter
public class Order {
    private final List<FoodItem> foodItems;
    private String customerName;
    private final OrderType orderType;

    public Order(OrderType orderType, List<FoodItem> foodItems, String customerName) {
        super();
        if (Objects.isNull(orderType)) {
            throw new IllegalArgumentException(
                    "Meal can't be order without selecting service 'Take Away' or 'Eat Here'");
        }

        if (Objects.isNull(foodItems) || foodItems.stream().noneMatch(Objects::nonNull)) {
            throw new IllegalArgumentException(
                    "Meal can't be order without any food item");
        }

        this.orderType = orderType;
        this.foodItems = new ArrayList<FoodItem>(foodItems);
        this.customerName = customerName;
        if (this.customerName == null) {
            this.customerName = "NO NAME";
        }
    }
}
